package com.kly.cashmall.module.splash.presenter;


import com.kly.cashmall.bean.ProtocolBean;
import com.kly.cashmall.bean.UpdateBean;
import com.kly.cashmall.framework.mvp.BaseViewPresenter;
import com.kly.cashmall.services.Network;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * @author
 */
public class SplashPresenter extends BaseViewPresenter<SplashViewer> {

    public SplashPresenter(SplashViewer viewer) {
        super(viewer);
    }

    @Override
    public void willDestroy() {

    }

    public void getAppCode() {
        rxManager.add(Network.getApi().getConfigAppCode().subscribeOn(Schedulers.io()).observeOn
                (AndroidSchedulers.mainThread()).subscribe(new Consumer<UpdateBean>() {
            @Override
            public void accept(UpdateBean bean) throws Exception {
                if (getViewer() != null) {
                    getViewer().getAppCodeSuccess(bean);
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (getViewer() != null) {
                    getViewer().getAppCodeFailed();
                }
            }
        }));
    }


    public void getProtocol() {
        rxManager.add(Network.getApi().getProtocol().subscribeOn(Schedulers.io()).observeOn
                (AndroidSchedulers.mainThread()).subscribe(new Consumer<ProtocolBean>() {
            @Override
            public void accept(ProtocolBean bean) throws Exception {
                if (getViewer() != null) {
                    getViewer().getProtocolSuccess(bean);
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                //返回异常 如404 503，或者返回的数据类型和我们定义的实体对象不一致
            }
        }));
    }
}